package com.gongpingjialoan.activity.main;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.gongpingjialoan.R;
import com.gongpingjialoan.activity.car.NewCarPriceActivity;
import com.gongpingjialoan.activity.fb.MyPushIntentService;
import com.gongpingjialoan.activity.particular.SecondActivity;
import com.gongpingjialoan.activity.sell.SellPrivateActivity;
import com.gongpingjialoan.activity.sell.WantSellCarActivity;
import com.gongpingjialoan.api.API;
import com.gongpingjialoan.bean.AssessmentData;
import com.gongpingjialoan.bean.Monitor;
import com.gongpingjialoan.bean.SellRecordBean;
import com.gongpingjialoan.bean.SellerValueBean;
import com.gongpingjialoan.cc.Const;
import com.gongpingjialoan.data.UserManager;
import com.gongpingjialoan.global.GPJApplication;
import com.gongpingjialoan.imageload.ImageLoad;
import com.gongpingjialoan.network.NetDataJson;
import com.gongpingjialoan.utility.DhUtil;
import com.gongpingjialoan.utility.JSONUtil;
import com.gongpingjialoan.utility.StepMonitor;
import com.gongpingjialoan.utility.StepRecord;
import com.gongpingjialoan.utility.TimeUtils;
import com.gongpingjialoan.view.AccurateDialog;
import com.gongpingjialoan.view.GetPhoneDialog;
import com.gongpingjialoan.view.LineChartView;
import com.gongpingjialoan.widget.LoadingDialog;
import com.google.gson.Gson;
import com.umeng.analytics.MobclickAgent;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 估值报告
 * huangcg
 */
public class ValueReportActivity extends BaseActivity {

    private ValueReportActivity mySelf = this;

    private TextView title_txt;
    private ImageView title_right;
    private final int RESULT_CONTACT = 1;

    private final int RESULT_LOGIN = 2;

    public static final int WANTSELL = 3;

    public String url = "";

    private UserManager mUserManager;


    private LoadingDialog loadingDialog;

    private AssessmentData ad = AssessmentData.getInstance();

    private String fromType;

    private NetDataJson mSellValueNetDataJson;

    private NetDataJson mSellRecordNetDataJson;

    private SellerValueBean mSellValueBean = new SellerValueBean();
    private SellRecordBean mSellRecordBean = new SellRecordBean();

    private ImageView pic;
    private TextView carName, mile, price, effluent_standard;
    private LinearLayout seller_ll, person_ll;
    private TextView good_tv, fail_tv, excellent_tv;
    private TextView half_year_decrease_tv;
    private Button sell_car_free_button;
    private boolean isPrivateSell = false;

    private ImageView seller_img;
    private ImageView person_img;
    private TextView seller_tv;
    private TextView person_tv;
    private LinearLayout sell_ll;
    private TextView sellto_tv;
    private boolean isLoadState = true;
    private LinearLayout more_ll;
    private LinearLayout sell_record_ll;
    private TextView load_state_tv;
    private ImageView load_state_img;
    private TextView price_detail_tv;
    private boolean isRecordCompleted = false;
    private boolean isValueCompleted = false;
    private LinearLayout include_sell_record_ll;
    private TextView sell_time;
    private GetPhoneDialog getPhoneDialog;
    LineChartView chartView;
    private View seller_view, person_view;

    JSONObject sellJo;
    TextView linechart_desT;

    @Override
    public void onBackPressed() {
        //表示从推送而来
//        if (MyPushIntentService.RECKON.equals(fromType)) {
//            Intent intent = new Intent(this, MainActivity.class);
//            startActivity(intent);
//            finish();
//        } else {
//            super.onBackPressed();
//        }
    }

    @Override
    public void initTitleBar() {
        View backV = findViewById(R.id.title_back);
        if (backV != null) {
            backV.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View arg0) {
//                    onBackPressed();
                    finish();
                }
            });
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        isSendData = true;
        action = "eval_sell";
        super.onCreate(savedInstanceState);
        loadingDialog = new LoadingDialog(mySelf);
        setContentView(R.layout.value_report_activity);
        initView();
        initSellValue();
        initSellRecord();
    }

    private void initSellRecord() {
        mSellRecordNetDataJson = new NetDataJson(new NetDataJson.OnStringListener() {
            @Override
            public void onDataJsonError(String errorMessage) {
                isRecordCompleted = true;
                if (isRecordCompleted && isValueCompleted) {
                    loadingDialog.dismiss();
                }
                Toast.makeText(ValueReportActivity.this, errorMessage, Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onDataJsonUpdate(String json) {
                isRecordCompleted = true;
                if (isRecordCompleted && isValueCompleted) {
                    loadingDialog.dismiss();
                }
                Gson gson = new Gson();
                mSellRecordBean = gson.fromJson(json, SellRecordBean.class);
                if ("success".equals(mSellRecordBean.getStatus())) {
                    addRecordView();

                } else {
                    Toast.makeText(ValueReportActivity.this, mSellRecordBean.getMsg(), Toast.LENGTH_SHORT).show();
                }
            }
        }, 1);
        mSellRecordNetDataJson.setUrl(API.sell_record);
        mSellRecordNetDataJson.addParam("city", ad.getCity());
        mSellRecordNetDataJson.addParam("brand", ad.getBrandSlug());
        mSellRecordNetDataJson.addParam("model", ad.getModelSlug());
        mSellRecordNetDataJson.addParam("model_detail", ad.getModelDetailSlug());
        mSellRecordNetDataJson.addParam("intent", "sell");
        mSellRecordNetDataJson.request("get");
        if (!loadingDialog.isShowing()) {
            loadingDialog.show();
        }
    }

    private void addRecordView() {
        sell_record_ll.removeAllViews();
        if (mSellRecordBean.getData() == null) {

            return;
        }

        //筛选数据
        List<SellRecordBean.DataBean> list = mSellRecordBean.getData();
        List<SellRecordBean.DataBean> filterData = filterDeallHistory(list, isPrivateSell);
        int size = filterData.size();
        findViewById(R.id.deal_hitsory_des).setVisibility(size == 0 ? View.GONE : View.VISIBLE);
        if (size <= 3) {
            more_ll.setVisibility(View.GONE);
        } else {
            more_ll.setVisibility(View.VISIBLE);
            if (isLoadState) {
                size = 3;
                load_state_tv.setText("查看更多 ");
                load_state_img.setSelected(false);
//                if (isPrivateSell) {
//                    PointRecordManage.getInstance().addPoint(mySelf, Piont.ReckonSellResultPersonTabMore);
//                } else {
//                    PointRecordManage.getInstance().addPoint(mySelf, Piont.ReckonSellResultDealerTabMore);
//                }


            } else {
                load_state_tv.setText("收起  ");
                load_state_img.setSelected(true);
            }

        }
        if (size > 0) {
            include_sell_record_ll.setVisibility(View.VISIBLE);
            for (int i = 0; i < size; i++) {
                View view = LayoutInflater.from(this).inflate(R.layout.sell_record_item, null);
                TextView model_txt = (TextView) view.findViewById(R.id.model_txt);
                TextView carName = (TextView) view.findViewById(R.id.carName);
                TextView price = (TextView) view.findViewById(R.id.price);
                TextView detail = (TextView) view.findViewById(R.id.detail);
                TextView time = (TextView) view.findViewById(R.id.time);
                SellRecordBean.DataBean data = filterData.get(i);
                carName.setText(data.getModel_zh() + " " + data.getModel_detail_zh());
                price.setText(data.getPrice());
                detail.setText(data.getMile() + "万公里 | " + data.getYear() + "年上牌 | " + data.getCity());
                time.setText("成交于" + TimeUtils.timeFormat(data.getDeal_time()));
                if (data.getModel_detail_slug().equals(ad.getModelDetailSlug())) {
                    model_txt.setVisibility(View.VISIBLE);
                } else {
                    model_txt.setVisibility(View.GONE);
                }
                sell_record_ll.addView(view);
            }
        }
    }

    private List<SellRecordBean.DataBean> filterDeallHistory(List<SellRecordBean.DataBean> data, boolean isPrivateSell) {
        List<SellRecordBean.DataBean> list = new ArrayList<>();
        for (int i = 0; i < data.size(); i++) {
            SellRecordBean.DataBean bean = data.get(i);
            //代表选中的是个人的
            if (isPrivateSell) {
                if (bean.getDeal_type().equals("private_party")) {
                    list.add(bean);
                }
            } else {
                if (!bean.getDeal_type().equals("private_party")) {
                    list.add(bean);
                }
            }

        }

        return list;
    }

    private void initSellValue() {

        mSellValueNetDataJson = new NetDataJson(new NetDataJson.OnStringListener() {
            @Override
            public void onDataJsonError(String errorMessage) {
                isValueCompleted = true;
                if (isRecordCompleted && isValueCompleted) {
                    loadingDialog.dismiss();
                }
                Toast.makeText(ValueReportActivity.this, errorMessage, Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onDataJsonUpdate(String json) {
                try {
                    sellJo = new JSONObject(json);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                isValueCompleted = true;
                if (isRecordCompleted && isValueCompleted) {
                    loadingDialog.dismiss();
                }
                if (!GPJApplication.getInstance().isLogin() && getSharedPreferences("GetPhone", MODE_PRIVATE).getBoolean("isShowGetPhoneDialog", true)) {
//                    showGetPhoneDialog();
                }

                findViewById(R.id.value_ll).setVisibility(View.VISIBLE);
                Gson gson = new Gson();
                mSellValueBean = gson.fromJson(json, SellerValueBean.class);
                if ("success".equals(mSellValueBean.getStatus())) {
                    ImageLoad.LoadImage(pic, Const.IMG_BASE + mSellValueBean.getData().getModel_info().getThumbnail(), R.drawable.brandnull, R.drawable.brandnull, ValueReportActivity.this);
                    carName.setText(mSellValueBean.getData().getModel_info().getModel_zh() + " " + mSellValueBean.getData().getModel_detail_info().getModel_detail_zh());
                    mile.setText(ad.getYear() + "年" + ad.getMonth() + "月上牌/" + ad.getMile() + "万公里");
                    price.setText(mSellValueBean.getData().getModel_detail_info().getPrice_bn() + "万");
                    effluent_standard.setText(mSellValueBean.getData().getModel_detail_info().getEmission_standard());
                    if (mSellValueBean.getData().getValue4s_model_range() != null && mSellValueBean.getData().getValue4s_model_range().size() > 0) {
                        price_detail_tv.setVisibility(View.VISIBLE);
                        List<Double> rangePrice = mSellValueBean.getData().getValue4s_model_range();
                        if (rangePrice.size() >= 2) {
                            if (rangePrice.get(0).equals(rangePrice.get(1))) {
                                price_detail_tv.setText(rangePrice.get(0) + "万");
                            } else {
                                price_detail_tv.setText(rangePrice.get(0) + "万-" + rangePrice.get(1) + "万");
                            }
                        } else {
                            price_detail_tv.setVisibility(View.GONE);
                        }
                        price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                    } else {
                        price_detail_tv.setVisibility(View.GONE);
                    }
                    setCarConditionData();
                    isPrivateSell = false;
                    JSONObject eval_pricesJo = null;
                    JSONObject half_year_decreaseJo = null;
                    if (sellJo != null) {
                        eval_pricesJo = JSONUtil.getJSONObject(sellJo, "data.eval_prices");
                        half_year_decreaseJo = JSONUtil.getJSONObject(sellJo, "data.half_year_decrease");
                    }
                    linechart_desT.setText("车商收购市场行情");
                    chartView.setLineColor(getResources().getColor(R.color.line_blue));
                    chartView.setPointDrawable(R.drawable.circle_blue);
                    bindChartView(JSONUtil.getJSONObject(half_year_decreaseJo, "sell_graph"));
                } else {
                    Toast.makeText(ValueReportActivity.this, mSellValueBean.getMsg(), Toast.LENGTH_SHORT).show();
                }
            }
        }, 1);
        mSellValueNetDataJson.setUrl(API.sell_value);
        mSellValueNetDataJson.addParam("brand", ad.getBrandSlug());
        mSellValueNetDataJson.addParam("model", ad.getModelSlug());
        mSellValueNetDataJson.addParam("model_detail", ad.getModelDetailSlug());
        mSellValueNetDataJson.addParam("year", ad.getYear());
        mSellValueNetDataJson.addParam("month", ad.getMonth());
        mSellValueNetDataJson.addParam("city", ad.getCity());
        mSellValueNetDataJson.addParam("mile", ad.getMile());
        mSellValueNetDataJson.request("get");
        if (!loadingDialog.isShowing()) {
            loadingDialog.show();
        }
    }

    private void showGetPhoneDialog() {
        if (getPhoneDialog == null) {
            getPhoneDialog = new GetPhoneDialog(ValueReportActivity.this);
            getPhoneDialog.setOnPickResultListener(new GetPhoneDialog.OnPickResultListener() {
                @Override
                public void onResult(int result) {
                    finish();
                }
            });
        }
        getPhoneDialog.show(DhUtil.sp2px(this, 180));
        MobclickAgent.onEvent(this, "ReckonMobileAlertShow");
    }

    private void setCarConditionData() {
        if (isPrivateSell) {
            sell_time.setText("*预计交易周期3~4周");
            good_tv.setText("¥" + String.valueOf(mSellValueBean.getData().getEval_prices().getPrivateX().getGood()) + "万");
            fail_tv.setText("¥" + String.valueOf(mSellValueBean.getData().getEval_prices().getPrivateX().getFair()) + "万");
            excellent_tv.setText("¥" + String.valueOf(mSellValueBean.getData().getEval_prices().getPrivateX().getExcellent()) + "万");
            half_year_decrease_tv.setText(String.valueOf(String.format("贬值%s万元", String.valueOf(mSellValueBean.getData().getHalf_year_decrease().getPrivateX()))));
        } else {
            sell_time.setText("*预计交易周期1~2天");
            good_tv.setText("¥" + String.valueOf(mSellValueBean.getData().getEval_prices().getSell().getGood()) + "万");
            fail_tv.setText("¥" + String.valueOf(mSellValueBean.getData().getEval_prices().getSell().getFair()) + "万");
            excellent_tv.setText("¥" + String.valueOf(mSellValueBean.getData().getEval_prices().getSell().getExcellent()) + "万");
            half_year_decrease_tv.setText(String.valueOf(String.format("贬值%s万元", String.valueOf(mSellValueBean.getData().getHalf_year_decrease().getSell()))));
        }
    }


    private void initView() {
        chartView = (LineChartView) findViewById(R.id.chartview);
        title_txt = (TextView) this.findViewById(R.id.top_title);
        title_right = (ImageView) this.findViewById(R.id.right_accuracy);
        title_right.setVisibility(View.VISIBLE);
        seller_view = findViewById(R.id.seller_view);
        person_view = findViewById(R.id.person_view);
        title_right.setBackgroundResource(R.drawable.juedebuzhun);
        title_right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                PointRecordManage.getInstance().addPoint(mySelf, Piont.ReckonSellResultFeedbackClick);
                AccurateDialog accurateDialog = new AccurateDialog(ValueReportActivity.this);
                accurateDialog.setOnPickResultListener(new AccurateDialog.OnPickResultListener() {

                    @Override
                    public void onResult(int result) {
                        if (result == 1) {
//                            title_right.setBackgroundResource(R.drawable.yitijiao);
//                            title_right.setEnabled(false);
                        }
                    }
                });
                accurateDialog.show();
            }
        });
        title_txt.setText("爱车估值详情");

        pic = (ImageView) findViewById(R.id.pic);
        carName = (TextView) findViewById(R.id.carName);
        mile = (TextView) findViewById(R.id.mile);
        price = (TextView) findViewById(R.id.price);
        effluent_standard = (TextView) findViewById(R.id.effluent_standard);
        seller_ll = (LinearLayout) findViewById(R.id.seller_ll);
        person_ll = (LinearLayout) findViewById(R.id.person_ll);
        good_tv = (TextView) findViewById(R.id.good_tv);
        fail_tv = (TextView) findViewById(R.id.fail_tv);
        excellent_tv = (TextView) findViewById(R.id.excellent_tv);
        half_year_decrease_tv = (TextView) findViewById(R.id.half_year_decrease_tv);
        sell_car_free_button = (Button) findViewById(R.id.sell_car_free_button);
        seller_img = (ImageView) findViewById(R.id.seller_img);
        person_img = (ImageView) findViewById(R.id.person_img);
        seller_tv = (TextView) findViewById(R.id.seller_tv);
        person_tv = (TextView) findViewById(R.id.person_tv);
        sell_ll = (LinearLayout) findViewById(R.id.sell_ll);
        sellto_tv = (TextView) findViewById(R.id.sellto_tv);
        more_ll = (LinearLayout) findViewById(R.id.more_ll);
        sell_record_ll = (LinearLayout) findViewById(R.id.sell_record_ll);
        load_state_tv = (TextView) findViewById(R.id.load_state_tv);
        load_state_img = (ImageView) findViewById(R.id.load_state_img);
        price_detail_tv = (TextView) findViewById(R.id.price_detail_tv);
        sell_time = (TextView) findViewById(R.id.sell_time);
        more_ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isLoadState = !isLoadState;
                addRecordView();
            }
        });
        linechart_desT = (TextView) findViewById(R.id.linechart_des);
        include_sell_record_ll = (LinearLayout) findViewById(R.id.include_sell_record_ll);
        findViewById(R.id.linear2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mSellValueBean.getData().getValue4s_model_range() != null && mSellValueBean.getData().getValue4s_model_range().size() > 0) {
                    Intent i = new Intent(ValueReportActivity.this, NewCarPriceActivity.class);
                    i.putExtra("city", ad.getCity());
                    i.putExtra("model_detail", ad.getModelDetailSlug());
                    i.putExtra("price_range", price_detail_tv.getText().toString());
                    i.putExtra("price", mSellValueBean.getData().getModel_detail_info().getPrice_bn());
                    i.putExtra("image", Const.IMG_BASE + mSellValueBean.getData().getModel_info().getThumbnail());
                    i.putExtra("title", carName.getText().toString());
                    startActivity(i);
                }

            }
        });
        businessSell();

        sell_car_free_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                toLoan();
//                assSubmitNEW();
            }
        });
        seller_ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                PointRecordManage.getInstance().addPoint(mySelf, Piont.ReckonSellResultDealerTab);
                isPrivateSell = false;

                setCarConditionData();
                businessSell();

                JSONObject eval_pricesJo = null;
                JSONObject half_year_decreaseJo = null;
                if (sellJo != null) {
                    eval_pricesJo = JSONUtil.getJSONObject(sellJo, "data.eval_prices");
                    half_year_decreaseJo = JSONUtil.getJSONObject(sellJo, "data.half_year_decrease");
                }
//                bindPriceView(JSONUtil.getJSONObject(eval_pricesJo, "sell"));
                chartView.setLineColor(getResources().getColor(R.color.line_blue));
                chartView.setPointDrawable(R.drawable.circle_blue);
                bindChartView(JSONUtil.getJSONObject(half_year_decreaseJo, "sell_graph"));
                linechart_desT.setText("车商收购市场行情");
                addRecordView();

            }
        });
        person_ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                PointRecordManage.getInstance().addPoint(mySelf, Piont.ReckonSellResultPersonTab);
                isPrivateSell = true;
                sellto_tv.setText("卖给个人");
                seller_img.setSelected(false);
                person_img.setSelected(true);
                seller_tv.setTextColor(getResources().getColor(R.color.text_grey_dark));
                seller_view.setVisibility(View.INVISIBLE);
                person_view.setVisibility(View.VISIBLE);
                person_tv.setTextColor(getResources().getColor(R.color.new_color));
                sell_ll.setSelected(true);
                setCarConditionData();
                JSONObject eval_pricesJo = null;
                JSONObject half_year_decreaseJo = null;
                if (sellJo != null) {
                    eval_pricesJo = JSONUtil.getJSONObject(sellJo, "data.eval_prices");
                    half_year_decreaseJo = JSONUtil.getJSONObject(sellJo, "data.half_year_decrease");
                }
                chartView.setLineColor(getResources().getColor(R.color.line_orange));
                chartView.setPointDrawable(R.drawable.circle_orange_n);
                bindChartView(JSONUtil.getJSONObject(half_year_decreaseJo, "private_graph"));
                linechart_desT.setText("个人交易市场行情");
                addRecordView();
            }
        });

        Bundle bundle = this.getIntent().getExtras();
        fromType = bundle.getString("type", "");
        //推送用
        String source = bundle.getString("source", "");
        String job_id = bundle.getString("job_id", "");
        if (fromType.equals(MyPushIntentService.RECKON)) {
            String vaule = bundle.getString("typevalue", "");
            StepRecord.recordStep(this, "pushnotification", "{type:" + fromType + ",typevalue:" + vaule + ",source:" + source + ",job_id:" + job_id + "}");
            setAssessmentPushData(vaule);
        } else {
            url = bundle.getString("url");
        }


        mUserManager = new UserManager(mySelf);
        mUserManager = mUserManager.LoadUserInfo();


    }

    private void businessSell() {
        sellto_tv.setText("卖给商家");
        seller_img.setSelected(true);
        person_img.setSelected(false);
        seller_tv.setTextColor(getResources().getColor(R.color.new_color));
        person_tv.setTextColor(getResources().getColor(R.color.text_grey_dark));
        seller_view.setVisibility(View.VISIBLE);
        person_view.setVisibility(View.INVISIBLE);
        sell_ll.setSelected(false);
    }


    //brand/model/modeldetail/year-month/mileage,形如audi/audi-a4/3621_ah/2008-4/2.50/nanjing
    public void setAssessmentPushData(String value) {
        try {
            String[] datas = value.split("/");
            ad.setBrandSlug(datas[0]);
            ad.setBrandName(datas[0]);
            ad.setModelSlug(datas[1]);
            ad.setModelName("");
            ad.setModelDetailName(getIntent().getStringExtra("description"));
            ad.setModelDetailSlug(datas[2]);
            ad.setMile(datas[4]);
            ad.setCity(getIntent().getStringExtra("city"));
            ad.setStatus("");
            ad.setCar_id("");
            String times[] = datas[3].split("-");
            ad.setYear(times[0]);
            ad.setMonth(times[1]);

        } catch (Exception e) {

        }
    }


    private void bindChartView(JSONObject jo) {


        JSONArray jsa = JSONUtil.getJSONArray(jo, "price_point");
        if (jsa == null) {
            return;
        }
        float[][] xypoints = new float[5][];
        String[] xtext
                = new String[5];
        String[] ytext
                = new String[5];
        for (int i = 0; i < jsa.length(); i++) {
            try {
                JSONArray injsa = (JSONArray) jsa.get(i);
                float[] a = new float[2];
                a[0] = i + 0.5f;
                a[1] = Float.parseFloat(injsa.get(1) + "");
                xypoints[i] = a;
                xtext[i] = injsa.get(0) + "";
                ytext[i] = injsa.get(1) + "万";
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }

//        float[][] xypoints = {{0.5f, JSONUtil.get}, {1.5f, 28}, {2.5f, 27}, {3.5f, 23}, {4.5f, 22}};


        chartView.setYmax(JSONUtil.getFloat(jo, "high_point"), JSONUtil.getFloat(jo, "low_point"));
        chartView.setXtexts(xtext);
        chartView.setYtexts(ytext);
        chartView.setXypoints(xypoints);
    }


    @Override
    protected void onDestroy() {
//        PointRecordManage.getInstance().addPoint(mySelf, Piont.ReckonResultBack);
        action = "eval_sell";
        if (mSellValueNetDataJson != null) {
            mSellValueNetDataJson.cancelTask();
        }
        if (mSellRecordNetDataJson != null) {
            mSellRecordNetDataJson.cancelTask();
        }
        super.onDestroy();
    }

    public void toLoan(){
        Intent it = new Intent(mySelf, SecondActivity.class);
        it.putExtra("from", "car_detail");
        it.putExtra("price", mSellValueBean.getData().getModel_detail_info().getPrice_bn());
        it.putExtra("brand", ad.getBrandSlug());
        it.putExtra("brand_zh", ad.getBrandName());
        it.putExtra("model", ad.getModelSlug());
        it.putExtra("model_zh", ad.getModelName());
        it.putExtra("modeldetail", ad.getModelDetailName());
        it.putExtra("year_string", DhUtil.getYearFromDetail(ad.getYear()));
        it.putExtra("mile", DhUtil.getMileFromDetail(ad.getMile()));
        startActivity(it);

    }

    public void assSubmitNEW() {
        StepMonitor.getInstance().addMonitor(new Monitor("click", "eval_sell_submit", System.currentTimeMillis(), 1f));

        if (GPJApplication.getInstance().isLogin()) {
            Intent intent = null;

            if (isPrivateSell) {
//                PointRecordManage.getInstance().addPoint(mySelf, Piont.ReckonSellResultPersonTabSell);
                intent = new Intent(this, SellPrivateActivity.class);
            } else {
//                PointRecordManage.getInstance().addPoint(mySelf, Piont.ReckonSellResultDealerTabSell);
                intent = new Intent(this, WantSellCarActivity.class);
            }
            startActivity(intent);
        } else {
            // 没有登陆
            Intent it = new Intent(mySelf, LoginActivity.class);
            startActivityForResult(it, RESULT_LOGIN);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Intent intent = null;
        if (resultCode == Activity.RESULT_OK) {
            switch (requestCode) {

                case RESULT_LOGIN:
                    if (isPrivateSell) {
                        intent = new Intent(this, SellPrivateActivity.class);
                    } else {
                        intent = new Intent(this, WantSellCarActivity.class);
                    }
                    startActivity(intent);
                    break;
                case RESULT_CONTACT:
                    intent = getIntent();
                    setResult(Activity.RESULT_OK, intent);
                    mySelf.finish();
                    break;
                case WANTSELL:
                    finish();
                    break;
                default:
                    break;
            }
        }

    }


}